import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLineEdit, QLabel

from PyQt6.QtWidgets import QGroupBox, QTabWidget, QStackedWidget, QFormLayout

class ContainerWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("容器和布局示例")
        self.resize(600, 400)
        
        main_layout = QVBoxLayout()
        
        # 1. 分组框
        group_box = QGroupBox("用户信息")
        form_layout = QFormLayout()
        form_layout.addRow("姓名:", QLineEdit())
        form_layout.addRow("年龄:", QLineEdit())
        form_layout.addRow("邮箱:", QLineEdit())
        group_box.setLayout(form_layout)
        
        # 2. 选项卡
        tab_widget = QTabWidget()
        
        # 选项卡1
        tab1 = QWidget()
        tab1_layout = QVBoxLayout()
        tab1_layout.addWidget(QLabel("这是第一个选项卡"))
        tab1.setLayout(tab1_layout)
        
        # 选项卡2
        tab2 = QWidget()
        tab2_layout = QHBoxLayout()
        tab2_layout.addWidget(QPushButton("按钮1"))
        tab2_layout.addWidget(QPushButton("按钮2"))
        tab2.setLayout(tab2_layout)
        
        tab_widget.addTab(tab1, "基本信息")
        tab_widget.addTab(tab2, "高级设置")
        
        # 3. 堆叠窗口
        stacked_widget = QStackedWidget()
        
        page1 = QLabel("这是第一页内容")
        page2 = QLabel("这是第二页内容")
        
        stacked_widget.addWidget(page1)
        stacked_widget.addWidget(page2)
        
        # 切换按钮
        switch_button = QPushButton("切换页面")
        switch_button.clicked.connect(
            lambda: stacked_widget.setCurrentIndex(
                1 if stacked_widget.currentIndex() == 0 else 0
            )
        )
        
        # 添加到主布局
        main_layout.addWidget(group_box)
        main_layout.addWidget(tab_widget)
        main_layout.addWidget(stacked_widget)
        main_layout.addWidget(switch_button)
        
        self.setLayout(main_layout)

# 使用容器窗口
app = QApplication(sys.argv)
window = ContainerWindow()
window.show()
sys.exit(app.exec())
